package dapps.entity.user;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.OrderBy;

import dapps.entity.IdEntity;
import dapps.entity.monitor.Element;

/**
 * 项目类型.
 * 
 */
@Entity
@Table(name = "type")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Type extends IdEntity implements Serializable {
		
	/**
	 * 
	 */
	private static final long serialVersionUID = -1153407727194898293L;


	@Column(nullable=false,unique=true)
	private String name;
	
	@Column(nullable=false,unique=true)
	private Integer tid;
	
	private Integer chooseable;
	
	private Set<Element> elements = new HashSet<Element>(0);
	
	private Set<User> users = new HashSet<User>(0);
	
	public Integer getChooseable() {
		return chooseable;
	}

	public void setChooseable(Integer chooseable) {
		this.chooseable = chooseable;
	}

	public Integer getTid() {
		return tid;
	}

	public void setTid(Integer tid) {
		this.tid = tid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "type")
	@OrderBy(clause="id asc")
    public Set<Element> getElements() {
            return elements;
    }
	

	public void setElements(Set<Element> elements) {
		this.elements = elements;
	}
	

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "type")
	@OrderBy(clause="code asc")
    public Set<User> getUsers() {
            return users;
    }
	

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public String toString() {
		return this.getName();
	}

}